In [16]:
import pandas as pd
import pyflux as pf
import matplotlib.pyplot as plt
from fbprophet import Prophet
%matplotlib inline
plt.rcParams['figure.figsize']=(20,10)
plt.style.use('ggplot')
In [11]:
sales_df = pd.read_csv('../examples/retail_sales.csv', index_col='date', parse_dates=True)
In [12]:
sales_df.head()
Out[12]:
Like all good modeling projects, we need to take a look at the data to get an idea of what it looks like.
In [15]:
sales_df.plot()
Out[15]:
It's pretty clear from this data that we are looking at a trending dataset with some seasonality. This is actually a pretty good datset for prophet since the additive model and prophet's implemention does well with this type of data.
With that in mind, let's take look at what prophet does from a modeling standpoint to compare with the dynamic linear regression model. For more details on this, you can take a look at my blog post titled Forecasting Time Series data with Prophet – Part 4 (http://pythondata.com/forecasting-time-series-data-prophet-part-4/)
In [17]:
# Prep data for prophet and run prophet
df = sales_df.reset_index()
df=df.rename(columns={'date':'ds', 'sales':'y'})
model = Prophet(weekly_seasonality=True)
model.fit(df);
future = model.make_future_dataframe(periods=24, freq = 'm')
future.tail()
forecast = model.predict(future)
model.plot(forecast);
With our prophet model ready for comparison, let's build a model with pyflux's dynamic linear regresion model.
In [21]:
sales_df['revenue'] = sales_df.sales
In [22]:
model = pf.DynReg('revenue ~ sales', data=sales_df)
In [23]:
model.plot_fit(figsize=(15,15))
In [ ]: